/*
 * @Author: hejian@myhexin.com 
 * @Date: 2019-01-18 14:22:54 
 * @Last Modified by: hejian@myhexin.com
 * @Last Modified time: 2019-01-23 17:11:20
 */
$(function () {
	var vueInit = null;
	vueInit = new Vue({
		el: "#vuewrap",
		data: {
			androidApp: getPlatform() == 'gphone' ? true : false,
			wan:10000,
			yi: 100000000,
			requestData: {
				code: getParam('stockcode'),
				date: getParam('date'),
				size: getParam('size'),
				marketid: getParam('marketid')
			},
			stock: {
				name: decodeURI(getParam('name')),
				code: getParam('code'),
				num: getParam('boardNum')
			},
			detailArr: [],
			headerArr: []
		},
		methods: {
			jumpFenshi: function () {
				var code = this.requestData.code;
				var marketid = this.requestData.marketid;
				thsStats.jumpNativeStat('todayhq', "fenshi", '2205', {
					targid: "stock_" + code
				});
				var url = "client.html?action=ymtz^stockcode=" + code + "^marketid=" + marketid + "^webid=2205"
				setTimeout(function () {
					location.href = url;
				}, 20);
			},
			getDetailData: function () {
				var that = this;
				var data = {
					stockcode: that.requestData['code'],
					date: that.requestData['date'],
					size: that.requestData['size']
				}
				ajax(hxmConfig.boardDetailApi, data, function (res) {
					$("#initLoading").addClass("hide");
					if (res.errorcode == 0) {
						that.detailArr = res.result;
						for (var i = 0; i < that.detailArr.length; i++) {
							if (that.detailArr[i]['date']) {
								that.detailArr[i]['date'] = Jen.transNumToDate(that.detailArr[i]['date'])
							};
						}
						that.headerArr = that.detailArr[0];
					}
				}, function (err) {
					$("#initLoading").addClass("hide");
					$("#errLoading").removeClass("hide");
				})
			},
			// 监听滚动事件
			listenScroll: function () {
				var that = this;
				var dpr = $("html").data("dpr") ? $("html").data("dpr") : 1;
				var bottomd1 = true;
				// 滚动到底部埋点
				$(window).on('scroll', function () {
					var windowHeight =
						getPlatform() == "iphone" ?
						window.screen.height :
						$(window).height(); //window高度
					var totalHeight = $(document).height() / dpr; //页面总高度
					var scrollHeight = $(window).scrollTop() / dpr; //window距顶部距离
					if (
						(scrollHeight + 10 >= totalHeight - windowHeight) &&
						scrollHeight != 0
					) {
						if (bottomd1) {
							thsStats.clickStat("compoundDetail", "bottom");
							bottomd1 = false;
						}
					}
				})
			},
			reload: function () {
				var that = this;
				$("#initLoading").removeClass("hide");
				$("#errLoading").addClass("hide");
				that.getDetailData();
			}
		},
		filters:{
			//用于数值或隐式数值类型
			textFilter:function (val,typeTag) {
				if(isNaN(val) || (!val && val != '0')){
					if(val && val != 'NaN'){
						return val
					}else{
						return '--'
					}
				}else{
					if(!typeTag){
						return val
					}else{
						return val + typeTag
					}
				}
			}
		},
		created: function () {
			$("#initLoading").removeClass("hide");
		},
		mounted: function () {
			var that = this;
			thsStats.pageStat('compoundDetail')
			setTimeout(function () {
				that.listenScroll();
				that.getDetailData();
			})
		}
	})
})